package cn.com.guage.dtm.metadata.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.metadata.domain.MdSys;
import cn.com.guage.dtm.metadata.service.IMdSysService;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.common.core.page.TableDataInfo;

/**
 * 系统定义Controller
 * 
 * @author liujun
 * @date 2021-06-24
 */
@Controller
@RequestMapping("/metadata/sys")
public class MdSysController extends BaseController
{
    private String prefix = "metadata/sys";

    @Autowired
    private IMdSysService mdSysService;

    @RequiresPermissions("metadata:sys:view")
    @GetMapping()
    public String sys()
    {
        return prefix + "/sys";
    }

    /**
     * 查询系统定义列表
     */
    @RequiresPermissions("metadata:sys:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MdSys mdSys)
    {
        startPage();
        List<MdSys> list = mdSysService.selectMdSysList(mdSys);
        return getDataTable(list);
    }

    /**
     * 导出系统定义列表
     */
    @RequiresPermissions("metadata:sys:export")
    @Log(title = "系统定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MdSys mdSys)
    {
        List<MdSys> list = mdSysService.selectMdSysList(mdSys);
        ExcelUtil<MdSys> util = new ExcelUtil<MdSys>(MdSys.class);
        return util.exportExcel(list, "系统定义数据");
    }

    /**
     * 新增系统定义
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统定义
     */
    @RequiresPermissions("metadata:sys:add")
    @Log(title = "系统定义", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MdSys mdSys)
    {
        return toAjax(mdSysService.insertMdSys(mdSys));
    }

    /**
     * 修改系统定义
     */
    @GetMapping("/edit/{sysId}")
    public String edit(@PathVariable("sysId") Long sysId, ModelMap mmap)
    {
        MdSys mdSys = mdSysService.selectMdSysById(sysId);
        mmap.put("mdSys", mdSys);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统定义
     */
    @RequiresPermissions("metadata:sys:edit")
    @Log(title = "系统定义", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MdSys mdSys)
    {
        return toAjax(mdSysService.updateMdSys(mdSys));
    }

    /**
     * 删除系统定义
     */
    @RequiresPermissions("metadata:sys:remove")
    @Log(title = "系统定义", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mdSysService.deleteMdSysByIds(ids));
    }
}
